#include <sys/_stdint.h>
/**
0.96 ST7735 demo

  | ST7735 pin     |  PICO Pin  | ESP8826 Pin       | STM32F1x pin |  Air001 pin  |
  | ---------------| ---------- | -----------       | ------------ | ------------ |
  |     SCL        |     GP18   |      D5 GPIO14    |     PA5      |   PA5
  |     SDA        |     GP19   |      D7 GPIO13     |     PA7     |   PA0
  |     DC         |     GP20   |      D3 GPIO0     |     PA1      |   PA1
  |     CS         |     GP17   |      D8 GPIO15    |     PA2      |   PA2 
  |     BLK        |            |             |              |

*/
#include <cstdint>

//#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <Adafruit_GFX.h>     // Core graphics library
#include <Adafruit_ST7735.h>  // Hardware-specific library for ST7735
#include <SPI.h>
//#elif defined(ESP8266) || defined(ARDUINO_RASPBERRY_PI_PICO_W)

//#endif



//#define ST77XX_GREEN 0x07E0


#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
#define TFT_SCL 6 //18  //CLK 6
#define TFT_SDA 7 //19  //MOSI 7
#define TFT_RST 3 //21  //RESET 5
#define TFT_DC  4 //20   //DC 6
#define TFT_CS  5 //17   //CS 5
//#define TFT_BLK
#elif defined(ESP8266)
#define TFT_CS 15
#define TFT_RST 12
#define TFT_DC 0
#define TFT_SCL 14  //CLK D5
#define TFT_SDA 13  //MOSI D7

#elif defined(__STM32F1__)
#define TFT_DC PA1
#define TFT_CS PA2
#define TFT_RST PA0
#elif defined(__AIR001xx_HAL_CONF_DEFAULT_H)  // Air001
#define TFT_DC PA1
#define TFT_CS PA4
#define TFT_RST PA0

#else

#define TFT_CS 15
#define TFT_RST 12
#define TFT_DC 0
#define TFT_SCL 14  //CLK D5
#define TFT_SDA 13  //MOSI D7

#endif

class Console {
public:

  virtual void print(const char * text, uint8_t size) = 0;
  virtual void print(const char * text, int16_t x, int16_t y, uint8_t size) = 0;
  virtual void print(const char * text, uint16_t color, uint8_t size) = 0;
  virtual void print(const char * text, int16_t x, int16_t y, uint16_t color, uint8_t size) = 0;

  virtual void println(const char * text) = 0;
  virtual void println(const char * text, uint8_t size) = 0;
  virtual void println(const char * text, uint16_t color, uint8_t size) = 0;
  virtual void println(const char * text, int16_t x, int16_t y, uint8_t size) = 0;
  virtual void flush() = 0;
};

class TaomuST7735 : public Console {
public:
  TaomuST7735();
  virtual ~TaomuST7735();

  void print(const char * text, uint8_t size);
  void print(const char * text, uint16_t color, uint8_t size);
  void print(const char * text, int16_t x, int16_t y, uint16_t color, uint8_t size);
  void print(const char * text, int16_t x, int16_t y, uint8_t size);

  void println(const char * text);
  void println(const char * text, uint8_t size);
  void println(const char * text, uint16_t color, uint8_t size);
   void println(const char * text, int16_t x, int16_t y, uint8_t size);
  void flush();
private:
  Adafruit_ST7735* st7735;
};
